import { Navigate, type RouteObject } from 'react-router-dom'
import React from 'react'
import { lazy } from 'react'
const CreateOrder = lazy(() => import('@/views/CreateOrder'))
const Detail = lazy(() => import('@/views/Detail'))
const Home = lazy(() => import('@/views/Home'))
const Layout = lazy(() => import('@/views/Layout'))
const Login = lazy(() => import('@/views/Login'))
const Order = lazy(() => import('@/views/Order'))
const User = lazy(() => import('@/views/User'))
const Map = lazy(() => import('@/views/Map'))
const Search = lazy(() => import('@/views/Search'))
const Agent = lazy(() => import('@/components/Agent'))
import RouterAuth from './RouterAuth'

// 后面加上懒加载
const router: RouteObject[] = [
  {
    path: '/pz',
    element: (
      <RouterAuth>
        <Layout />
      </RouterAuth>
    ),
    children: [
      { path: '/pz', element: <Navigate to="home" /> },
      { path: 'home', element: <Home /> },
      { path: 'order', element: <Order /> },
      { path: 'user', element: <User /> }
    ]
  },
  { path: '/', element: <Navigate to="/login" /> },
  { path: '/login', element: <Login /> },
  {
    path: '/corder',
    element: (
      <RouterAuth>
        <CreateOrder />
      </RouterAuth>
    )
  },
  {
    path: '/detail',
    element: (
      <RouterAuth>
        <Detail />
      </RouterAuth>
    )
  },
  {
    path: '/map',
    element: (
      <RouterAuth>
        <Map />
      </RouterAuth>
    )
  },
  {
    path: '/search',
    element: (
      <RouterAuth>
        <Search />
      </RouterAuth>
    )
  },
  {
    path: '/agent',
    element: (
      <RouterAuth>
        <Agent />
      </RouterAuth>
    )
  }
]

export default router
